﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace GestionCompte.Models.ManageCategory
{
    public class AddCategory : ManageCategoryModel
    {

        public String textName {get; set;}
        public bool isOneShot {get; set;}

        public AddCategory()
        {
            textName = null;
            isOneShot = false;
        }

        public bool AddToDb()
        {
            using(var context = new EntityAccess.ModelContainer()) 
            {
                EntityAccess.CategoryEntity categoryToAdd = new EntityAccess.CategoryEntity();
                categoryToAdd.Name = textName;
                categoryToAdd.IsOneShot = isOneShot;
                var db = context.Set<EntityAccess.CategoryEntity>();
                db.Add(categoryToAdd);
                context.SaveChanges();
                return true;
            }
            
        }
    }
}
